package com.bdqn.business.system.controller;

import com.bdqn.response.Result;
import com.bdqn.response.ResultCode;
import com.bdqn.utils.UploadUtils;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/upload")
public class UploadImageController {

    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    @RequestMapping(value = "/image",method = RequestMethod.POST)
    public Result uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
        String uploadFile = UploadUtils.createUploadFile(fastFileStorageClient, file);
        String url = "http://47.97.77.138:8888/" + uploadFile; //group1/M00/00/00/wKiHhF-P9_SAKOYpAACv_3NkrIU461.png
        return new Result(ResultCode.SUCCESS,url);
    }

}
